/****************************************************************************
 *
 *  LinuxChatty
 *  Copyright (C) 2010, David Hsu.
 * 
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 ***************************************************************************/
#ifndef _RESOURCETABLE_H_
#define _RESOURCETABLE_H_

#include "xml/tinyxml.h"
#include <vector>
#include <string>

/**
 * Structure for holding the key press for the menu item, title text, and
 * a small description
 */
struct MenuItem
{
	int key;
	std::string keyText;
	std::string data;
	std::string title;
	std::string desc;
};
 
/**
 * Structure for holding radio button information for the servers
 */
struct RadioItem
{
	std::string name;
	std::string url;
	bool selected;
};

/**
 * Simple information about the application.
 */
struct AppInfo
{
    std::string title;
    std::string version;
};

/**
 * ResourceTable
 *
 * Data driven resource table that contains all data used in the program.
 * Currently, all data is stored in an XML file.
 */
class ResourceTable
{
public:
	ResourceTable();
	ResourceTable(const char * file);
	
	// Load the xml file that contains all the program info.
	// Returns True if succeeded
	bool LoadFile(const char * file);
	
	// Saves the settings to the file
	bool SaveFile();
	
	// Get the application title and version
	const std::string& GetTitle() const;
	const std::string& GetVersion() const;
	
	// Returns the list of menu items to display
	const std::vector<MenuItem>& GetMenuList() const;
	// Return a specific item from the list
	MenuItem GetMenuListItem(unsigned int index);
	// Accessor functions for the menu list
	unsigned int NumMenuItems() const;
	unsigned int GetMaxMenuLength() const;
	
	// Accessor functions for the selected server, custom server, and
	// authentication
	const std::vector<RadioItem>& GetServerList() const;
	const std::string& GetCustomServerURL() const;
	const std::string& GetSelectedServer() const;
	const std::string& GetAuthentication() const;
	
	// Set the values for the server and authentication information
	void SetSelectedServer(const std::string& serverName);
	void SetCustomServerURL(const std::string& url);
	void SetAuthorization(const std::string& auth);
	
private:
	// XML Document so it can load and modify the XML resource file
	TiXmlDocument xmlDoc;
	
	// App information
	AppInfo appInfo;
	
	// List of menu items to display in the main menu
	std::vector<MenuItem> menuList;
	
	// Length of the longest title.  Used to center and format the items
	unsigned int maxMenuTitleLength;
	
	// List of servers to choose from
	std::vector<RadioItem> serverList;
	
	// Custom server URL
	std::string customServerURL;
	
	// Selected server URL to use
	std::string selectedServer;
	
	// Authentication data
	std::string authentication;
};

#endif
